package xyz.yuzegod.megawalls.command;

import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.game.Game;
import xyz.yuzegod.megawalls.game.stage.GameStage;

public class CommandStage extends BaseCommand
{
    public CommandStage() {
        super("stage");
        this.setPermission("MegaWalls.admin");
    }
    
    @Override
    public String getPossibleArguments() {
        return "<stage>";
    }
    
    @Override
    public int getMinimumArguments() {
        return 1;
    }
    
    @Override
    public void execute(final CommandSender sender, final String label, final String[] args) throws CommandException {
        final Game game = MegaWalls.getInstance().getGame();
        if (game == null) {
            sender.sendMessage("§c§l未获取到游戏对象,无法强制开启游戏！");
            return;
        }
        try {
            final int priority = Integer.parseInt(args[0]);
            final GameStage stage = game.getStageManager().getStage(priority);
            if (stage == null) {
                sender.sendMessage("§c找不到游戏阶段！");
                return;
            }
            game.getStageManager().setCurrentStage(stage.getPriority() + 1);
            stage.excute(game);
            sender.sendMessage("§a执行成功！");
        }
        catch (Exception ex) {}
    }
    
    @Override
    public boolean isOnlyPlayerExecutable() {
        return false;
    }
}
